<!--
 * @Author: your name
 * @Date: 2020-07-18 03:14:30
 * @LastEditTime: 2020-07-24 19:08:52
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /waibao/iuyun-device-web/wechat/src/components/pages/devicefinance.vue
-->
<template>
    <div class="container">
        <div class="pageTop">
            <span class="iconfont backHistory" @click="spotCheckView">&#xe6eb;</span>
            <span class="sellWorkOrder_header_title">工单设备财务记录列表</span>
            <span class="iconfont"   v-focusable @click="backToHomepage" style="float:right;line-height:48px;font-size:17px;margin-right:15px;">&#xe668;</span>
        </div>
        <div class="content">
            <div class="top" v-show="financialTableData.length!=0">
                <span class="fl">工单编号：{{orderId}}</span>
            </div>
            <div v-show="financialTableData.length==0" class="not-content">
              <img src="/static/img/zwlr-icon.png" class="img4">
              <div class="title">暂无数据</div>
            </div>
            <mescroll-vue class="me_scroll" ref="mescroll6" :down="mescrollDown6" :up="mescrollUp6" @init="mescrollInit6">
                <div class="financeCard" :class="{active1:activeIndex == index}" @click="showdetails(item.recordId,index)" v-for="(item,index) in financialTableData" :key="index">
                  <div class="row">
                    <div><span>所属部门：</span><span>{{item.departmentName}}</span></div>
                    <div class="btn" :class="{'green':item.type == 1,'blue':item.type == 2,'red':item.type == 3}">
                      {{item.type == 1 ? "新购" : item.type == 2 ? "维修" : item.type == 3 ? "更换" : ""}}
                      </div>
                  </div>
                  <div class="row">
                    <div><span>设备名称：</span><span>{{item.deviceName}}</span></div>
                    <div><span  style="padding-left: 30px;">部件名称：</span><span>{{item.componentName}}</span></div>
                  </div>
                    <div class="line"></div>
                    <div class="bottom">
                      <span style="text-align:left;padding-left: 10px;">实际金额：¥ {{item.actualAmount.toFixed(2)}}<div class="verLine"></div></span>
                      <span>提交时间：{{item.time | filtterTime}}</span>
                    </div>
                </div>
              </mescroll-vue>
        </div>
        <div class="submit-btn" @click="addRecord" v-if="status == 5 && isAuth">添加设备财务记录</div>
    </div>
</template>

<script>
import MescrollVue from "mescroll.js/mescroll.vue";
import DeviceDao from '../../daos/device_dao'

export default {
    name: "workOrderFinance",
        //返回首页的公共方法
    inject: ["backToHomepage"],
    components:{
        MescrollVue,
    },
    data() {
       return {
           noData:false,
           show:false,
            mescroll6: null,
            mescrollDown6: {},
            mescrollUp6: {
              that: this,
              callback: this.upCallback6,
              page: {
                num: 0,
                size: 20
              },
              htmlNodata: '<p class="upwarp-nodata">-- 暂无更多的数据 --</p>',
              noMoreSize: 5,
              toTop: {
                src: "./static/mescroll-totop.png",
                offset: 1000
              },
              isBounce:false,
            },
            financialTableData:[],
            maintainPay:'', //维修花费 ,
            maintainTotal:'', //维修记录数 ,
            newBuyPay:'', //新购花费 ,
            newBuyTotal:'', //新购记录数 ,
            replacePay:'', //更换花费 ,
            replaceTotal:'', //更换记录数 ,
            effectiveTotal:'', //有效记录数 ,
            totalPay:'', // 总花费
            searchForm:{
                operatorType:"",
                submitTime:[],
                status:"",
                departmentId:'',
                deviceId:'',
                componentId:'',
                maxMoney:'',
                mixMoney:''
            },
            activeIndex:-1,
            status:2,
            isAuth:false,

       }
    },
    watch: {
      $route (to, from) {
        // this.getPageType(to.name)
        if(to.name == "workOrderFinance"){
          this.upCallback6({num:1,size:20},this.mescroll6);
        }
      },
    },
    computed: {
        orderId(){
            return this.$route.query.id
        }
    },
    beforeRouteEnter(to, from, next) {
      next(vm => {
        vm.activeIndex = -1;
      });
    },
    methods: {
      addRecord(){
        this.$router.push({name:"addFinance",query:{isAdd:true,orderId:this.orderId,departmentId:this.$route.query.departmentId}})
      },
        showdetails(id,index){
          this.activeIndex = index
          setTimeout(()=>{
            this.$router.push({path: '/manage/deviceDetailManage/financeDetail', query: {recordId: id}});
          },200)
        },
        spotCheckView(){
            history.back(-1)
        },
        mescrollInit6(mescroll) {
          this.mescroll6 = mescroll;
        },
        //设备财务记录
        upCallback6(page, mescroll) {
          DeviceDao.getWorkOrderRecord({thirdpartySourceId:this.orderId}, res => {
            let data = res
            if (data) {
              if (page.num === 1) {
                this.financialTableData = [];
                if(data.record.length==0){
                    this.noData = true
                }
              }
                let user = JSON.parse(localStorage.getItem("user"))
                if(user.id == data.operatorId){
                  this.isAuth = true
                }
                this.status = data.status
                this.noData = false
                this.financialTableData = this.financialTableData.concat(data.record);
                this.maintainPay = data.maintainPay //维修花费 ,
                this.maintainTotal = data.maintainTotal//维修记录数 ,
                this.newBuyPay = data.maintainTotal//新购花费 ,
                this.newBuyTotal = data.newBuyTotal//新购记录数 ,
                this.replacePay = data.replacePay //更换花费 ,
                this.replaceTotal = data.replaceTotal //更换记录数 ,
                this.effectiveTotal = data.effectiveTotal //有效记录数 ,
                this.totalPay = data.totalPay // 总花费
              this.$nextTick(() => {
                mescroll.endByPage(data.record.length, data.total);
                // mescroll.endSuccess(res.record.length);
              });
            } else {
              mescroll.endErr();
            }
          });
        },
    },
    filters:{
        //设备类型过滤
        ruleText(val){
            let type = ''
            _this.ruleTypeList.forEach(item=>{
                if(item.indicator == val){
                    type = item.dataTypeName
                }
            })
            return type
        },
        filtterTime(val){
          if(val){
            return val.split(' ')[0]
          }
        }
      },
}
</script>

<style lang="less" scoped>
    @import '../../styles/iconfont.css';
.submit-btn{
  position: fixed;
  bottom: 25px;
  left: 50%;
  margin-left: -40%;
  background-color: #456de6;
  width: 80%;
  height: 40px;
  line-height: 40px;
  color: #fff;
  border-radius: 20px;
  text-align: center;
  font-size: 14px;
  touch-action: none;

}
.container{
    height: 100%;
    width: 100%;
}
    .pageTop{
        height: 48px;
        color: #fff;
        position: fixed;
        width: 100%;
        left: 0px;
        top: 0px;
        background-color: #22233f;
        z-index: 9;
            .backHistory{
        transform:rotate(90deg);
        -ms-transform:rotate(90deg); 	/* IE 9 */
        -moz-transform:rotate(90deg); 	/* Firefox */
        -webkit-transform:rotate(90deg); /* Safari 和 Chrome */
        -o-transform:rotate(90deg);
        line-height:48px;
        font-size:25px !important;
        margin-left:10px;
        touch-action: none;
    }
        .sellWorkOrder_header_title{
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 16px;
        }
    }
    .content{
        width: 100%;
        height: 100%;
        padding: 0 10px;
        box-sizing: border-box;
        padding-top:50px;
        -webkit-overflow-scrolling: touch;
        background: #1b1c32;
            padding-bottom: 80px;
        .top{
            display: inline-block;
            width: 100%;
            margin: 10px 0;
            margin-top: 18px;
            span{
                display: inline-block;
                &:first-child{
                    padding-left: 20px;
                    font-size: 14px;
                    color: #fff;
                }
            }
            .fr{
                float: right;
            }
            .fl{
                float: left;
            }
            .iconfont{
                margin-right: 10px;
                font-size: 14px;
            }
            .icon2{
                transform:rotate(90deg);
                -ms-transform:rotate(90deg); 	/* IE 9 */
                -moz-transform:rotate(90deg); 	/* Firefox */
                -webkit-transform:rotate(90deg); /* Safari 和 Chrome */
                -o-transform:rotate(90deg);
            }
        }
    }
      .financeCard{
        border-radius: 4px;
        background:#292A4D;
        margin-bottom: 12px;
        position: relative;
        transition: .2s all ease-in-out;
        color:#fff;
        margin: 7px 0px;
        font-size: 14px;
          padding: 15px 0px;
          &.active1{
        background: #383A69;
      }
          .btn{
            padding: 2px 10px;
            border-radius: 10px;
            font-size: 12px;
          }
          .green{
            background-color: #67C23A;
          }
          .blue{
            background-color: #409EFF;
          }
          .red{
            background-color: #F56C6C;
          }
        .line{
          width: 100%;
          height:1px;
          background:rgba(255,255,255,0.1);
          margin: 10px 0;
        }
        .row{
          display: flex;
          padding: 0px 10px;
          margin-bottom: 8px;
          justify-content: space-between;
                    div{
            display: flex;
            flex: 0 0 auto;
            span{
                &:last-child{
                  display: inline-block;
                  width: 85px;
                  white-space: nowrap;
                  text-overflow: ellipsis;
                  overflow: hidden;
                  word-break: break-all;
                }
            }
          }
        }
        .bottom{
          display: flex;
          justify-content: space-between;
          span{
            position: relative;
            display: inline-block;
            width: 50%;
            text-align: center;
          }
          .verLine{
            position: absolute;
            right:1px;
            top: 0;
            width: 1px;
            height: 20px;
            background:rgba(255,255,255,0.1);

          }

        }
  }
    .financeTable{
    padding: 0 15px;
    color:#fff;
    font-size: 14px;
            margin-bottom: 20px;

    table{
      width: 100%;
      border-color:#fff;
      border-style: solid;
      border-width:1px 0px 0px 1px;
      border-spacing: 0;
    }
    tr{
      td{
        text-align: center;
        padding: 10px 0;
        border-bottom: 1px solid #fff;
         border-right: 1px solid #fff;
      }
    }
  }
    .not-content{
        margin:30px auto;
        text-align: center;
        img{
          width: 64px;
          height: 64px;
          margin-left: 20px;
        }
        /*.img4{*/
          /*margin-top:70px;*/
        /*}*/
        .title{
          margin: 8px auto;
          width:126px;
          height:40px;
          font-size:14px;
          font-family:PingFangSC-Regular,PingFang SC;
          font-weight:400;
          color:rgba(158,198,251,1);
          line-height:20px;
          text-align: center;
        }
      }
</style>
